package com.ssm.dboss;

import org.slf4j.Logger;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class DbUtils {

    static Logger logger;

    public static void main(String[] args) {
        // db   全仓
        //'39606912' btc7,'35837542' btc6
        // redis apo 12074089
        System.out.println(Math.abs("41082642".hashCode()) % 9 + 1);
        System.out.println(Math.abs("41072098".hashCode()) % 24 + 2);
        //System.out.println(Math.abs("41257022".hashCode()) % 13 + 2);

        // XX 处理线程池
        ThreadPoolExecutor threadExecutor = new ThreadPoolExecutor(5, 20,
                5, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1), new ThreadFactory() {
            final AtomicInteger threadNumber = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r, "xxx-xxx-thread[" + threadNumber.getAndIncrement() + "]-");
                t.setDaemon(true);
                return t;
            }
        }, (task, executor) -> {
            try {
                executor.getQueue().put(task);
            } catch (InterruptedException e) {
                logger.error("线程阻断异常:" + e.getMessage(), e);
            }
        });
    }
}
